package someTestExcemple.huaweiOd.regularExpression;
//华为OD机试 - 解压报文 - 正则表达式（Java 2024 E卷 100分）
//https://blog.csdn.net/guorui_java/article/details/142693103
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UnZipString {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String input = s.nextLine();
        System.out.print(calculate(input));
    }

    public static String calculate(String input) {
        if (input == null || "".equals(input)) {
            return "";
        }

        Pattern pattern = Pattern.compile("[0-9]+\\[[a-z]+]");

        Matcher matcher = pattern.matcher(input);
        //递归结束条件
        if (!matcher.find()) {
            return input;
        }

        //找到匹配的字符子串，比如5[good]
        String group = matcher.group();
        int index = group.indexOf('[');
        int counts = Integer.parseInt(group.substring(0, index));
        String words = group.substring(index + 1, group.length() - 1);

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < counts; ++i) {
            builder.append(words);
        }
        //字符串替换
        String find = input.replace(group, builder.toString());
        //递归再次调用
        return calculate(find);
    }
}
